package cn.fl.grpcfg.service.impl;

import java.util.List;

import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.grpcfg.service.ISplGrpPrjBizViewService;
import cn.fl.grpcfg.transform.SplGrpPrjBizViewVOTransform;
import cn.fl.grpcfg.vo.SplGrpPrjBizViewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.grpcfg.api.ISplGrpPrjBizViewApiService;
import fl.spl.facade.grpcfg.condition.SplGrpPrjBizViewQC;
import fl.spl.facade.grpcfg.dto.SplGrpPrjBizViewDTO;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.Pager;


/**
 * @Description: 集团经销商挂靠业务数据视图 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SplGrpPrjBizViewServiceImpl implements ISplGrpPrjBizViewService {

	/**
	 * 自定义 API 自行注入需要的API服务
	 */
	@Autowired
	private ISplGrpPrjBizViewApiService splGrpPrjBizViewApiService;

	@Override
	public SplGrpPrjBizViewVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001, "获取对象主键不能为空!");
		}
		//TODO 业务逻辑
		SplGrpPrjBizViewDTO dto = null;
		//this.自定义ApiService.selectSplGrpPrjBizViewDTOById(id);
		return SplGrpPrjBizViewVOTransform.toVO(dto);
	}

	@Override
	public Long add(SplGrpPrjBizViewVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"新增对象不存在!");
		};
		//return this.splGrpPrjBizViewApiService.add(SplGrpPrjBizViewVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return null;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		//return this.splGrpPrjBizViewApiService.removeSplGrpPrjBizViewDTOById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
	@Override
    public boolean removeByIds(List<Long> ids)throws BaseException{
		if(CollectionUtils.isEmpty(ids)){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"删除对象主键不能为空!");
		};
		return false;
    }

	@Override
	public boolean modify(SplGrpPrjBizViewVO entity) throws BaseException{
		if(null == entity){
			throw new BaseException(BaseExceptionConstant.COMMON_0001,"修改对象不能为空!");
		};
		//return this.splGrpPrjBizViewApiService.modifySplGrpPrjBizViewDTO(SplGrpPrjBizViewVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		//TODO 业务逻辑
		Pager pager = this.splGrpPrjBizViewApiService.searchGrpMemberDataDTOByPage(page, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD);
		List<SplGrpPrjBizViewDTO> dtoList = (List<SplGrpPrjBizViewDTO>)pager.getResultList();
		List<SplGrpPrjBizViewVO> voList = SplGrpPrjBizViewVOTransform.toVOList(dtoList);
		pager.setResultList(voList);
		return pager;
	}

	@Override
	public List<SplGrpPrjBizViewVO> searchSplGrpMembDevAmtRank(SplGrpPrjBizViewQC qc) {
		// TODO Auto-generated method stub
		if(null == qc){
			return null;
		}
		return SplGrpPrjBizViewVOTransform.toVOList(this.splGrpPrjBizViewApiService.searchSplGrpMembDevAmtRank(qc));
	}
	
	@Override
	public Pager searchAsSureListPage(Pager page) throws BaseException{
		if(null == page){
			page = new Pager();
		}
		 Pager pager = this.splGrpPrjBizViewApiService.searchGrpLoanGuarDataDTOByPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.FL_WEB_CHL_CD);
		 
		 List<SplGrpPrjBizViewDTO> dtoList = (List<SplGrpPrjBizViewDTO>)pager.getResultList();
		 List<SplGrpPrjBizViewVO> voList = SplGrpPrjBizViewVOTransform.toVOList(dtoList);
		 pager.setResultList(voList);
		 return pager ;
	}
}
